home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 2002 Tom Parker (tom@carrott.org),
- Matthias Münch (matthias@amigaworld.de)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- In addition, as a special exception, Tom Parker and Matthias Münch give
- permission to link the code of this program with a TCP stack of your
- choice, any official MUI libraries or classes and any custom MUI classes
- that should be necessary for the operation of this program. This
- exception also gives you permission to distribute linked combinations
- including this software with any of the before-mentioned libraries and
- classes. You must obey the GNU General Public License in all respects for
- all of the code used other than that provided by the before-mentioned
- libraries and classes. As part of this exception you are obliged to
- follow the license terms of the before-mentioned libraries, this license
- does not compel you to follow those terms, but if you do not then you may
- not link with those libraries. If you modify this file, you may extend
- this exception to your version of the file, but you are not obligated to
- do so. If you do not wish to do so, delete this exception statement from
- your version.
- */
- /*
- ** Text.mui Subclass for Clickable URLs
- */
-
- #include <string.h>
-
- #include <proto/graphics.h>
- #include <proto/openurl.h>
-
- #include "url.h"
-
- ULONG url_new(struct IClass *cl, Object *obj, struct opSet *msg);
- ULONG url_setup(struct IClass *cl, Object *obj, Msg msg);
- ULONG url_minmax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg);
- ULONG url_draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg);
- ULONG url_cleanup(struct IClass *cl, Object *obj, Msg msg);
- ULONG url_clicked(struct IClass *cl, Object *obj, Msg msg);
-
-
- MUI_DISPATCH(url_dispatch)
- {
- switch(msg->MethodID) {
- case OM_NEW: return(url_new(cl,obj,(APTR)msg));
- /* case MUIM_Setup: return(url_setup(cl,obj,(APTR)msg));
- case MUIM_AskMinMax: return(url_minmax(cl,obj,(APTR)msg));
- case MUIM_Draw: return(url_draw(cl,obj,(APTR)msg));
- case MUIM_Cleanup: return(url_cleanup(cl,obj,(APTR)msg));
- */ case URL_CLICKED: return(url_clicked(cl,obj,(APTR)msg));
- }
- return(DoSuperMethodA(cl,obj,msg));
- }
-
-
- ULONG url_new(struct IClass *cl, Object *obj, struct opSet *msg)
- {
- struct urldata *data;
- char *name=NULL,*href=NULL,*help=NULL;
-
- name = (char *)GetTagData(URL_NAME,0,msg->ops_AttrList);
- href = (char *)GetTagData(URL_HREF,0,msg->ops_AttrList);
- help = (char *)GetTagData(URL_HELP,0,msg->ops_AttrList);
-
- obj = (Object *)DoSuperNew(cl,obj,
- MUIA_Text_Contents, name,
- MUIA_Text_PreParse, "\33u",
- /* MUIA_ShowSelState, FALSE,
- */ MUIA_InputMode, MUIV_InputMode_RelVerify,
- /* MUIA_ShortHelp, help, */
- TAG_MORE, msg->ops_AttrList);
-
- if(!obj) return(NULL);
-
- data = INST_DATA(cl,obj);
- data->href = href;
-
- DoMethod(obj,MUIM_Notify,MUIA_Pressed,FALSE,obj,1,URL_CLICKED);
- return((ULONG)obj);
- }
-
-
- ULONG url_setup(struct IClass *cl, Object *obj, Msg msg)
- {
- struct urldata *data = INST_DATA(cl,obj);
-
- if (!DoSuperMethodA(cl,obj,msg))
- return(FALSE);
-
- data->color = ObtainBestPen(_screen(obj)->ViewPort.ColorMap,0xffffffff,0,0,OBP_Precision,PRECISION_GUI,TAG_DONE);
-
- return(TRUE);
- }
-
-
- ULONG url_minmax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg)
- {
- struct urldata *data = INST_DATA(cl,obj);
- int x,y;
-
- DoSuperMethodA(cl,obj,(APTR)msg);
-
- x = _font(obj)->tf_XSize * data->len;
- y = _font(obj)->tf_YSize;
-
- msg->MinMaxInfo->MinWidth += x;
- msg->MinMaxInfo->DefWidth += x;
- msg->MinMaxInfo->MaxWidth += x;
- msg->MinMaxInfo->MinHeight += y;
- msg->MinMaxInfo->DefHeight += y;
- msg->MinMaxInfo->MaxHeight += y;
-
- return(0);
- }
-
-
- ULONG url_draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg)
- {
- struct urldata *data = INST_DATA(cl,obj);
- struct RastPort *rp = _rp(obj);
- struct TextFont *tf = _font(obj);
- int x,y;
- u_long p;
-
- DoSuperMethodA(cl,obj,(APTR)msg);
- if(!(msg->flags & MADF_DRAWOBJECT)) return(0);
-
- SetFont(rp,tf);
-
- if(!data->pixlen) {
- data->pixlen = TextLength(rp,data->name,data->len);
- data->pixlen += TextLength(rp,"<>",2);
- data->y = _mtop(obj) + tf->tf_Baseline + ( (_mheight(obj) - tf->tf_YSize) / 2 );
- }
-
- x = _mleft(obj);
- y = data->y;
-
- Move(rp,x,y);
- Text(rp,"<",1);
- p = GetAPen(rp);
- if(data->color != -1) SetAPen(rp,data->color);
- Text(rp,data->name,data->len);
- SetAPen(rp,p);
- Text(rp,">",1);
-
- if(data->color != -1) SetAPen(rp,data->color);
- Move(rp,x,y+3);
- Draw(rp,x+data->pixlen,y+3);
- SetAPen(rp,p);
-
- return(0);
- }
-
-
- ULONG url_cleanup(struct IClass *cl, Object *obj, Msg msg)
- {
- struct urldata *data = INST_DATA(cl,obj);
-
- if(data->color != -1) ReleasePen(_screen(obj)->ViewPort.ColorMap,data->color);
-
- return(DoSuperMethodA(cl,obj,msg));
- }
-
-
- ULONG url_clicked(struct IClass *cl, Object *obj, Msg msg)
- {
- struct urldata *data = INST_DATA(cl,obj);
-
- OpenURLBase = OpenLibrary("openurl.library",1);
- if(!OpenURLBase) return(0);
- URL_Open(data->href,TAG_DONE);
- CloseLibrary(OpenURLBase);
- return(0);
- }
-